package cn.edu.tju.wallet.controller;

import cn.edu.tju.core.model.HttpResult;
import cn.edu.tju.core.model.ResultCodeEnum;
import cn.edu.tju.wallet.dto.WalletBalanceDTO;
import cn.edu.tju.wallet.service.WalletQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/wallet")
public class WalletQueryController {

    @Autowired
    private WalletQueryService walletQueryService;

    /**
     * 查询余额接口（遵循指南，适配现成HttpResult）
     */
    @GetMapping("/balance")
    public HttpResult<WalletBalanceDTO> getBalance(@RequestParam Long userId) {
        try {
            WalletBalanceDTO balance = walletQueryService.getBalance(userId);
            return HttpResult.success(balance);
        } catch (Exception e) {
            return HttpResult.failure(ResultCodeEnum.SERVER_ERROR, e.getMessage());
        }
    }
}